package com.iter.devbox.util;

import java.util.ArrayDeque;
import java.util.LinkedList;

/**
 * Deque 双端队列，一个线性 collection，支持在两端插入和移除元素
 * 
 * @author Jimly
 */
public class MyDeque {

	public static void main(String[] args) {
		//Deque接口所有已知实现类：ArrayDeque, LinkedBlockingDeque, LinkedList
		ArrayDeque<String> arrayDeque = new ArrayDeque<String>();
		arrayDeque.addFirst("1");
		for (int i=2; i<100; i++) {
			arrayDeque.addLast(""+i);
		}
		System.out.println(arrayDeque.pollFirst());
		System.out.println(arrayDeque.getFirst());
		System.out.println(arrayDeque.getLast());
		
		System.out.println("...........................");
		LinkedList<String> linkedList = new LinkedList<String>();
		linkedList.addFirst("1");
		for (int i=2; i<500; i++) {
			linkedList.addLast(""+i);
		}
		System.out.println(linkedList.pollFirst());
		System.out.println(linkedList.getFirst());
		System.out.println(linkedList.getLast());
	}
}
